/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package technotheist.geo.map.scalar;

import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import technotheist.geo.map.Format;
import technotheist.geo.map.Map;

/**
 *
 * @author Mitchel Strachan
 */
public class FloatMap extends Map<FloatBuffer> {

    final FloatBuffer data;

    public FloatMap(int sideLength) {
        this(sideLength, 1);
    }

    public FloatMap(int sideLength, int components) {
        super(sideLength, components, Format.Float);
        this.data = ByteBuffer.allocateDirect(byteCount).asFloatBuffer();
    }

    public float get(int p, int u, int v) {
        return getFloat(p, u, v);
    }

    public void set(int p, int u, int v, float value) {
        setFloat(p, u, v, value);
    }

    public float get(int p, int u, int v, int component) {
        return getFloat(p, u, v, component);
    }

    public void set(int p, int u, int v, int component, float value) {
        setFloat(p, u, v, component, value);
    }

    @Override
    protected FloatBuffer data() {
        return data;
    }

    @Override
    public int getInt(int bufferIndex) {
        return (int) getFloat(bufferIndex);
    }

    @Override
    public float getFloat(int bufferIndex) {
        return data.get(bufferIndex);
    }

    @Override
    public void setInt(int bufferIndex, int value) {
        setFloat(bufferIndex, value);
    }

    @Override
    public void setFloat(int bufferIndex, float value) {
        data.put(bufferIndex, value);
    }

    public float get(int index) {
        return get(index, 0);
    }

    public float get(int index, int component) {
        if (component < 0 || component >= components) {
            throw new IllegalArgumentException("component must be between 0 and " + components);
        }
        return getFloat(index * components + component);
    }
}
